﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Shapes;

namespace TestApp
{
    class UIUtils
    {
        public static List<Line> draw_table(int left, int top, int number_of_row, int padding_of_row)
        {
            List<Line> lineList = new List<Line>();

            for (int i = 0; i <= number_of_row; i++)
            {
                Line myLine = new Line();
                myLine.X1 = left + i * padding_of_row;
                myLine.Y1 = top;
                myLine.X2 = left + i * padding_of_row;
                myLine.Y2 = top + padding_of_row * number_of_row;

                lineList.Add(myLine);
            }

            for (int i = 0; i <= number_of_row; i++)
            {
                Line myLine = new Line();
                myLine.X1 = left;
                myLine.Y1 = top + i * padding_of_row;
                myLine.X2 = left + padding_of_row * number_of_row;
                myLine.Y2 = top + i * padding_of_row;

                lineList.Add(myLine);
            }

            return lineList;
        }

        public static Color convertRGB(string strRGB)
        {
            var arr0 = strRGB.Split(',');
            byte[] arr1 = new byte[4];
            for (int j = 0; j < 4; j++)
            {
                arr1[j] = byte.Parse(arr0[j].Trim());
            }

            return Color.FromArgb(arr1[0], arr1[1], arr1[2], arr1[3]);
        }

        public static List<int> convertString(string strArr)
        {
            var arr0 = strArr.Split(',');
            List<int> list = new List<int>();

            for (int j = 0; j < arr0.Length; j++)
            {
                list.Add(int.Parse(arr0[j].Trim()));
            }

            return list;
        }

        //计算两点的直线斜率
        public static double caculate_k(double x1, double y1, double x2, double y2)
        {
            if (x1 == x2)
                return double.NaN;

            return (y2 - y1) / (x2 - x1);
        }

        //计算斜率对应的角度
        public static double caculate_angle(double k)
        {
            return Math.Atan(k);
        }

        //计算坐标轴旋转角度angle后，根据旋转后的值，计算旋转前的值
        public static List<double> getOldCoor(double x1, double y1, double angle)
        {
            double x = x1 * Math.Cos(angle) - y1 * Math.Sin(angle);
            double y = x1 * Math.Sin(angle) + y1 * Math.Cos(angle);

            return new List<double>() { x, y };
        }

        //计算坐标轴旋转角度angle后，根据旋转前的值，计算旋转后的值
        public static List<double> getNewCoor(double x1, double y1, double angle)
        {
            double x = x1 * Math.Cos(angle) + y1 * Math.Sin(angle);
            double y = -x1 * Math.Sin(angle) + y1 * Math.Cos(angle);

            return new List<double>() { x, y };
        }

        //计算两点间距离
        public static double get_distance(double x1, double y1, double x2, double y2)
        {
            return Math.Sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));
        }

        public static List<Coor> getThreePoints(double x1, double y1, double x2, double y2, double angel, double original_x, double original_y)
        {
            var old_list1 = getOldCoor(x1, y1, angel);
            var old_list2 = getOldCoor(x2, y2, angel);

            List<Coor> coorList1 = new List<Coor>();
            coorList1.Add(new Coor(old_list1[0] + original_x, old_list1[1] + original_y));
            coorList1.Add(new Coor(old_list2[0] + original_x, old_list2[1] + original_y));

            return coorList1;
        }
    }

    public class Coor
    {
        public Coor(double x, double y){
            this.x = x;
            this.y = y;
        }

        public double x;
        public double y;
    }
}
